package com.jinmdz.fmis.mapper.mapper.provider;

import com.jinmdz.fmis.mapper.entity.ColdStorageEquipmentEntity;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.jdbc.SQL;

/**
 * 冷藏设备表Provider
 *
 * @author generator
 * @date 2020-03-12 17:08
 */
public class ColdStorageEquipmentProvider {

    /**
     * 增加ColdStorageEquipment
     *
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-03-12 17:08
     */
    public String insertColdStorageEquipment(@Param("entity") ColdStorageEquipmentEntity entity) {
        return new SQL() {
            {
                INSERT_INTO(" cold_storage_equipment ");

                if (entity.getDeleted() != null) {
                    VALUES(" deleted ", " #{entity.deleted,jdbcType=TINYINT} ");
                }

                VALUES(" equipment_type_code ", " #{entity.equipmentTypeCode,jdbcType=SMALLINT} ");
                VALUES(" equipment_code ", " #{entity.equipmentCode,jdbcType=VARCHAR} ");
                VALUES(" equipment_describe ", " #{entity.equipmentDescribe,jdbcType=VARCHAR} ");
                VALUES(" equipment_state ", " #{entity.equipmentState,jdbcType=TINYINT} ");
                VALUES(" column_no ", " #{entity.columnNo,jdbcType=INTEGER} ");
                VALUES(" row_no ", " #{entity.rowNo,jdbcType=INTEGER} ");

                if (entity.getDisableState() != null) {
                    VALUES(" disable_state ", " #{entity.disableState,jdbcType=TINYINT} ");
                }

                VALUES(" sort ", " #{entity.sort,jdbcType=INTEGER} ");
                VALUES(" remark ", " #{entity.remark} ");
                VALUES(" funeral_parlour_code ", " #{entity.funeralParlourCode,jdbcType=VARCHAR} ");
                VALUES(" create_user_id ", " #{entity.createUserId,jdbcType=INTEGER} ");

                if (entity.getUnmodified() != null) {
                    VALUES(" unmodified ", " #{entity.unmodified,jdbcType=TINYINT} ");
                }

                VALUES(" modified_user_id ", " #{entity.modifiedUserId,jdbcType=INTEGER} ");
                VALUES(" version ", " unix_timestamp(now()) ");
            }
        }.toString();
    }

    /**
     * 修改ColdStorageEquipment
     *
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-03-12 17:08
     */
    public String updateColdStorageEquipment(@Param("entity") ColdStorageEquipmentEntity entity) {
        return new SQL() {
            {
                UPDATE(" cold_storage_equipment ");

                if (entity.getDeleted() != null) {
                    SET(" deleted = #{entity.deleted,jdbcType=TINYINT} ");
                }

                SET(" equipment_type_code = #{entity.equipmentTypeCode,jdbcType=SMALLINT} ");
                SET(" equipment_code = #{entity.equipmentCode,jdbcType=VARCHAR} ");
                SET(" equipment_describe = #{entity.equipmentDescribe,jdbcType=VARCHAR} ");
                SET(" equipment_state = #{entity.equipmentState,jdbcType=TINYINT} ");
                SET(" column_no = #{entity.columnNo,jdbcType=INTEGER} ");
                SET(" row_no = #{entity.rowNo,jdbcType=INTEGER} ");

                if (entity.getDisableState() != null) {
                    SET(" disable_state = #{entity.disableState,jdbcType=TINYINT} ");
                }

                SET(" sort = #{entity.sort,jdbcType=INTEGER} ");
                SET(" remark = #{entity.remark} ");
                SET(" funeral_parlour_code = #{entity.funeralParlourCode,jdbcType=VARCHAR} ");

                if (entity.getUnmodified() != null) {
                    SET(" unmodified = #{entity.unmodified,jdbcType=TINYINT} ");
                }

                SET(" modified_user_id = #{entity.modifiedUserId,jdbcType=INTEGER} ");
                SET(" version = unix_timestamp(now()) ");
                WHERE(" id = #{entity.id,jdbcType=INTEGER} ");
                WHERE(" unmodified = 0 ");
                WHERE(" version = #{entity.version,jdbcType=INTEGER} ");
            }
        }.toString();
    }

    /**
     * 查询ColdStorageEquipment列表
     *
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-03-12 17:08
     */
    public String listColdStorageEquipment(@Param("entity") ColdStorageEquipmentEntity entity) {
        return new SQL() {
            {
                StringBuilder builder = new StringBuilder();
                builder.append(" id,deleted,equipment_type_code,equipment_code,equipment_describe,equipment_state,column_no,row_no,disable_state,sort,remark,funeral_parlour_code,create_user_id,gmt_create,unmodified,modified_user_id,gmt_modified,version ");
                SELECT(builder.toString());
                FROM(" cold_storage_equipment ");

                if (entity.getEquipmentTypeCode() != null) {
                    WHERE(" equipment_type_code = #{entity.equipmentTypeCode,jdbcType=SMALLINT} ");
                }

                if (entity.getEquipmentCode() != null) {
                    WHERE(" equipment_code = #{entity.equipmentCode,jdbcType=VARCHAR} ");
                }

                if (entity.getEquipmentDescribe() != null) {
                    WHERE(" equipment_describe = #{entity.equipmentDescribe,jdbcType=VARCHAR} ");
                }

                if (entity.getEquipmentState() != null) {
                    WHERE(" equipment_state = #{entity.equipmentState,jdbcType=TINYINT} ");
                }

                if (entity.getColumnNo() != null) {
                    WHERE(" column_no = #{entity.columnNo,jdbcType=INTEGER} ");
                }

                if (entity.getRowNo() != null) {
                    WHERE(" row_no = #{entity.rowNo,jdbcType=INTEGER} ");
                }

                if (entity.getDisableState() != null) {
                    WHERE(" disable_state = #{entity.disableState,jdbcType=TINYINT} ");
                }

                if (entity.getSort() != null) {
                    WHERE(" sort = #{entity.sort,jdbcType=INTEGER} ");
                }

                if (entity.getRemark() != null) {
                    WHERE(" remark = #{entity.remark} ");
                }

                if (entity.getFuneralParlourCode() != null) {
                    WHERE(" funeral_parlour_code = #{entity.funeralParlourCode,jdbcType=VARCHAR} ");
                }

            }
        }.toString();
    }
}